﻿using System;
using rlTodayMakeSkin.Project.Attributes;
using System.Xml;
using System.Xml.Serialization;
using System.Drawing;
using System.Windows.Forms;
using rlTodayMakeSkin.Project.XmlElement.Properties;
using rlTodayMakeSkin.Project.XmlElement.XmlSubElements;

namespace rlTodayMakeSkin.Project.XmlElement
{
    /// <summary>
    /// Class that represents a Text element in skin.xml file
    /// </summary>
    public class rlText : ContainerSubElements
    {
        private string strText = "Text";
        private Color colore = Color.Black;
        private string align = Alignment.LEFT;

        public rlText(XmlNode n, rlTodayProject prj)
            : base(n, prj)
        {
            if (listaAtt["alignment"] != null) align = listaAtt["alignment"].Value;
            if (listaAtt["color"] != null) colore = GetColorFromRGB(listaAtt["color"].Value);
            initElement();
        }

        public rlText(rlTodayProject prj)
            : base(prj)
        {
            initElement();
        }

        public rlText() { } //for the serialization

        /***************
         PUBLIC MEMBERS
         **************/

        /// <summary>
        /// Gets, sets the text for this element
        /// </summary>
        [PropertyDescription("Text for this element")]
        [XmlAttribute("Text")]
        public string Title
        {
            get { return strText; }
            set { strText = value; }
        }

        /// <summary>
        /// Gets, sets the alignment of the text in the element
        /// </summary>
        [PropertyDescription("Alignment of the text", PropertyTypes.ALIGNMENT)]
        [XmlAttribute("alignment")]
        public string Align
        {
            get { return align; }
            set { align = value; }
        }

        /// <summary>
        /// Gets a string that represents color in RGB format
        /// </summary>
        [PropertyDescription("string that represents color in RGB format", ReadOnlyProperty=true)]
        [XmlAttribute("color")]
        public string RGBColor
        {
            get { return GetRGBFromColor(colore); }
            set { /*required by the XmlSerializer*/}
        }

        /// <summary>
        /// Gets, sets color text of this element
        /// </summary>
        [PropertyDescription("text color of this element", PropertyTypes.COLOR)]
        [XmlIgnore()]
        public Color TextColor
        {
            get { return colore; }
            set { colore = value; }
        }

        public override void DrawElement(Graphics g)
        {
            DrawString(g, strText, font, colore);
        }

        /************************
         PRIVATE MEMBERS
         **********************/
        /// <summary>
        /// Initializes property of element
        /// </summary>
        private void initElement(){
            strNome = "Text";
            hourHand = null;
        }

    }
}
